namespace DotNetNuke.Entities.Modules.Communications
{
    using System;
    using System.Web.UI;

    public class ModuleCommunicate
    {
        private DotNetNuke.Entities.Modules.Communications.ModuleCommunicators _ModuleCommunicators = new DotNetNuke.Entities.Modules.Communications.ModuleCommunicators();
        private DotNetNuke.Entities.Modules.Communications.ModuleListeners _ModuleListeners = new DotNetNuke.Entities.Modules.Communications.ModuleListeners();

        private int Add(IModuleCommunicator item)
        {
            int returnData = this._ModuleCommunicators.Add(item);
            int refIntHelperL0 = this._ModuleListeners.Count - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                IModuleListener listener1 = this._ModuleListeners[i];
                item.ModuleCommunication += new ModuleCommunicationEventHandler(listener1.OnModuleCommunication);
            }
            return returnData;
        }

        private int Add(IModuleListener item)
        {
            int returnData = this._ModuleListeners.Add(item);
            int refIntHelperL0 = this._ModuleCommunicators.Count - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                this._ModuleCommunicators[i].ModuleCommunication += new ModuleCommunicationEventHandler(item.OnModuleCommunication);
            }
            return returnData;
        }

        public void LoadCommunicator(Control ctrl)
        {
            if (ctrl is IModuleCommunicator)
            {
                this.Add((IModuleCommunicator) ctrl);
            }
            if (ctrl is IModuleListener)
            {
                this.Add((IModuleListener) ctrl);
            }
        }

        public DotNetNuke.Entities.Modules.Communications.ModuleCommunicators ModuleCommunicators
        {
            get
            {
                return this._ModuleCommunicators;
            }
        }

        public DotNetNuke.Entities.Modules.Communications.ModuleListeners ModuleListeners
        {
            get
            {
                return this._ModuleListeners;
            }
        }
    }
}

